//package com.example.tsbs.config;
//
//import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
//import com.example.tsbs.entity.UserInfo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
//public class LoginInterceptor implements HandlerInterceptor {
//
//    public static UserInfo loginUser;
//
//    @Autowired
//    private HttpSession httpSession;
//
//    //Controller逻辑执行之前
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
////        System.out.println("preHandle....");
//        String uri = request.getRequestURI();
////        System.out.println("当前路径："+uri);
//        /**
//         * HandlerMethod=>Controller中标注@RequestMapping的方法
//         *  需要配置静态资源不拦截时，添加这块逻辑  => 前后端分离项目
//         *
//         */
//        // 是我们的controller中的方法
//        if (!(handler instanceof HandlerMethod)) {
//            return true;
//        }
//
////        String token = "";
////        if(ObjectUtils.isNotEmpty(request.getHeader("token"))) {
////            token = request.getHeader("token");
////        } else {
////            HttpSession session = request.getSession();
////            token = (String) session.getAttribute("token");
////        }
//        String token = request.getHeader("token");
////        System.out.println(token);
//        if (ObjectUtils.isEmpty(token)) {
//            // 未登录跳转到登录界面
//            throw  new RuntimeException("no login! 用户未登录，请重新登录！");
//        }
//        String[] tokenTime = token.split("_");
//        //当前时间减去5小时
//        String hour = DateUtil.hourProcess(-5);
//
//        loginUser = TokenUtil.gentUser(token);
//        if (!TokenUtil.verify(token)) {
//            // 未登录跳转到登录界面
//            throw  new RuntimeException("no login! 用户未登录，请重新登录！");
//        } else if(hour.compareTo(tokenTime[1]) < 0){
//            System.out.println(Integer.parseInt(tokenTime[1]));
//            System.out.println(hour);
//            throw  new RuntimeException("token已过期，请重新登录！");
//        } else {
//            return true;
//        }
//    }
//
//    //Controller逻辑执行完毕但是视图解析器还未进行解析之前
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
////        System.out.println("postHandle....");
//    }
//
//    //Controller逻辑和视图解析器执行完毕
//    @Override
//    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
////        System.out.println("afterCompletion....");
//    }
//
//
//
//}
